/**
 * 
 */
package com.ai.controller.system;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ai.common.controller.BaseController;
import com.ai.common.exception.AlikAssert;
import com.ai.common.model.Pagination;
import com.ai.common.model.Result;
import com.ai.mmd.system.dto.GkinfoDTO;
import com.ai.service.system.model.GkinfoModel;
import com.ai.service.system.service.IGkinfoService;

/**
 * 港口
 * 
 * @author Administrator
 *
 */
@RequestMapping("gk")
@Controller("com.ai.controller.system.GkController")
public class GkController extends BaseController {

	/**
	 * 列表
	 * @param gkinfoDTO
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("list")
	public Pagination<GkinfoModel> list(@ModelAttribute GkinfoDTO gkinfoDTO)
			throws Exception {
		if (gkinfoDTO.getSort()!=null) {
			gkinfoDTO.setSort(gkinfoDTO.getSort().concat(" " + gkinfoDTO.getOrder()));
		}else {
			gkinfoDTO.setSort("id desc");
		}
		return igkinfoService.getPagination(gkinfoDTO);
	}
	
	/**
	 * 编辑
	* @date 2016年6月27日 下午9:31:40
	* @param CclxInfoDTO
	* @return
	* @throws Exception
	* List<gkinfoModel>
	 */
	@ResponseBody
	@RequestMapping("neworedit")
	public Result neworedit(@ModelAttribute GkinfoDTO gkinfoDTO,
			@RequestParam(required = true) Integer isflag)
			throws Exception {
		Result rs = new Result(true);
		GkinfoModel gkinfoModel = new GkinfoModel();
		switch (isflag) {
		case 0:
			//新增
			AlikAssert.isNotNull(gkinfoDTO.getGkmc(), "参数异常.");
			gkinfoDTO.setCjsj(new Date());			
			BeanUtils.copyProperties(gkinfoDTO, gkinfoModel);
			igkinfoService.insert(gkinfoModel);
			break;
		case 1:
			//编辑
			AlikAssert.isNotNull(gkinfoDTO.getId(), "参数异常.");
			gkinfoDTO.setGxsj(new Date());
			BeanUtils.copyProperties(gkinfoDTO, gkinfoModel);
			igkinfoService.updateByPrimaryKey(gkinfoModel);
			break;
		case 2:
			//删除
			AlikAssert.isNotNull(gkinfoDTO.getId(), "参数异常.");
			gkinfoDTO.setSfsc(1);
			gkinfoDTO.setGxsj(new Date());
			BeanUtils.copyProperties(gkinfoDTO, gkinfoModel);
			igkinfoService.updateByPrimaryKey(gkinfoModel);
			break;
		default:
			break;
		}
				
		return rs;
	}
	
	/**
     * 跳转
     * @return
     * @throws Exception
     */
    @RequestMapping("forward")
    public String forward() throws Exception{
        return "system/gk/list";
    }
    
    /**
	 * 绑定列表
	 * @param gkinfoDTO
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("relist")
	public List<Map<String, Object>> relist(@ModelAttribute GkinfoDTO gkinfoDTO)
			throws Exception {
		
		gkinfoDTO.setSfsc(0);
		List<Map<String, Object>> list = igkinfoService.getreList(gkinfoDTO);
		
		return list;
	}

	@Resource(name = "igkinfoService")
	private IGkinfoService igkinfoService;

}
